package com.api.shopapi.mapper;

import com.api.shopapi.entity.ElderlyDrugRecord;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author maochuan
 */
@Repository
@Mapper
public interface ElderlyDrugRecordMapper {
    @Insert("insert into elderly_drug_record " +
            "(ElderlyDrugRecordCode,ElderlyCode,ElderlyName,Remarks,CreateTime,StaffCode,InstitutionCode) " +
            "value(#{elderlyDrugRecord.ElderlyDrugRecordCode},#{elderlyDrugRecord.ElderlyCode}," +
            "#{elderlyDrugRecord.ElderlyName},#{elderlyDrugRecord.Remarks},#{elderlyDrugRecord.CreateTime}," +
            "#{elderlyDrugRecord.StaffCode},#{elderlyDrugRecord.InstitutionCode})")
    int insert(@Param("elderlyDrugRecord") ElderlyDrugRecord elderlyDrugRecord);

    @Select("select * from elderly_drug_record where ElderlyDrugRecordCode=#{elderlyDrugRecordCode} limit 1")
    ElderlyDrugRecord getByElderlyDrugRecordCode(@Param("elderlyDrugRecordCode") String elderlyDrugRecordCode);

    @Select("<script>" +
            "select * from elderly_drug_record " +
            "where InstitutionCode=#{institutionCode} " +
            "and (CreateTime between #{startTime} and #{endTime}) " +
            "<if test ='elderlyName !=null and elderlyName!=\"\" '>" +
            "and ElderlyName like concat('%',#{elderlyName},'%') " +
            "</if>" +
            "order by CreateTime DESC" +
            "</script>")
    List<ElderlyDrugRecord> getPageList(@Param("institutionCode") String institutionCode,@Param("elderlyName") String elderlyName,
                                        @Param("startTime") String startTime,@Param("endTime") String endTime);
}
